package com.vivo.yc;

import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.Test;
import utils.DBConnectionPool;
import utils.JdbcUtil;

import java.sql.*;

public class testmy2 {

    private DBConnectionPool dbConnectionPool;
    private Connection connection;

    public static void main(String[] args) {
        System.out.print("ddd");
    }

    @Test
    public void test() {
        findpersion(12);
    }

    public void findpersion(int uid) {


        //3.创建执行sql语句的对象
//        Connection connection = JdbcUtil.getConnectionDB();

        try {
            if (dbConnectionPool == null) {
                dbConnectionPool = new DBConnectionPool();
            }
            connection = dbConnectionPool.getConnection();
            //4.创建sql语句
            String sql = "select * from user where uid>?";
            PreparedStatement pm = connection.prepareStatement(sql);
            pm.setInt(1, uid);
            ResultSet result = pm.executeQuery();

            if (result.next()) {
                System.out.print("查到了");
            } else {
                System.out.print("没查到..");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            dbConnectionPool.returnBackCoonToPool(connection);
        }

    }

}
